package com.dyh.quickdemozwei.withdraw;

/**
 * @Author: yhdong
 * @Date: 2021/11/30 17:09
 */
public class ActionPlanExecutor {
    
    public static <P> void exe(P param,ActionPlan<P> actionPlan){


        int idx = 0;
        int planSize = actionPlan.getActions().size();
        for (;idx<planSize;idx++){

            ActionWrap<P> actionWrap = actionPlan.getActions().get(idx);
            ActionCtrl ctrl = new ActionCtrl();
            try {
                actionWrap.action.act(param,ctrl);
            } catch (Exception e) {

                break;
            }
            if (ctrl.shouldWithDraw)
                break;
        }

        if (idx==planSize)
            return;

        for(;idx>=0;idx--){
            ActionWrap<P> actionWrap = actionPlan.getActions().get(idx);
            if (actionWrap.deAction!=null){
                ActionCtrl ctrl = new ActionCtrl();
                actionWrap.deAction.act(param,ctrl);
            }
        }
    }
}
